package com.tjy.farmer.service.impl;

import java.util.List;

import com.tjy.common.utils.DateUtils;
import com.tjy.farmer.domain.FarmerAlarm;
import com.tjy.farmer.mapper.FarmerAlarmMapper;
import com.tjy.farmer.mapper.FarmerLocationInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tjy.farmer.mapper.FarmerInfoMapper;
import com.tjy.farmer.domain.FarmerInfo;
import com.tjy.farmer.service.IFarmerInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 蜂农信息Service业务层处理
 *
 * @author tjy
 * @date 2025-09-05
 */
@Service
public class FarmerInfoServiceImpl implements IFarmerInfoService {
    @Autowired
    private FarmerInfoMapper farmerInfoMapper;

    @Autowired
    private FarmerLocationInfoMapper farmerLocationInfoMapper;

    @Autowired
    private FarmerAlarmMapper farmerAlarmMapper;

    /**
     * 查询蜂农信息
     *
     * @param id 蜂农信息主键
     * @return 蜂农信息
     */
    @Override
    public FarmerInfo selectFarmerInfoById(Long id) {
        return farmerInfoMapper.selectFarmerInfoById(id);
    }

    /**
     * 查询蜂农信息列表
     *
     * @param farmerInfo 蜂农信息
     * @return 蜂农信息
     */
    @Override
    public List<FarmerInfo> selectFarmerInfoList(FarmerInfo farmerInfo) {
        return farmerInfoMapper.selectFarmerInfoList(farmerInfo);
    }

    /**
     * 新增蜂农信息
     *
     * @param farmerInfo 蜂农信息
     * @return 结果
     */
    @Override
    public int insertFarmerInfo(FarmerInfo farmerInfo) {
        farmerInfo.setCreateTime(DateUtils.getNowDate());
        return farmerInfoMapper.insertFarmerInfo(farmerInfo);
    }

    /**
     * 修改蜂农信息
     *
     * @param farmerInfo 蜂农信息
     * @return 结果
     */
    @Override
    public int updateFarmerInfo(FarmerInfo farmerInfo) {
        farmerInfo.setUpdateTime(DateUtils.getNowDate());
        return farmerInfoMapper.updateFarmerInfo(farmerInfo);
    }

    /**
     * 批量删除蜂农信息
     *
     * @param ids 需要删除的蜂农信息主键
     * @return 结果
     */
    @Override
    public int deleteFarmerInfoByIds(Long[] ids) {
        return farmerInfoMapper.deleteFarmerInfoByIds(ids);
    }

    /**
     * 删除蜂农信息信息
     *
     * @param id 蜂农信息主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFarmerInfoById(Long id) {
//        定位信息表
        farmerLocationInfoMapper.deleteFarmerLocationInfoByFarmerId(id);
//        报警信息表
        farmerAlarmMapper.deleteFarmerLocationInfoByFarmerId(id);
        return farmerInfoMapper.deleteFarmerInfoById(id);
    }
}
